﻿var monthValue = "月";
var currenDate = (new Date()).Format("yyyy-MM");
var s_text = document.getElementById("s_text");
if (s_text != null && s_text != undefined) {
    s_text.innerHTML = currenDate + monthValue;
}
mini.parse();
var tree = mini.get("treegrid");
tree.load({
    datetime: s_text.innerHTML.substr(0, s_text.innerHTML.length - 1)
});

function MonthChange(value) {
    if (s_text == null || s_text == undefined) return;
    var arrS = s_text.innerHTML.split("-");
    var date = new Date(arrS[0], arrS[1].substring(0, arrS[1].length - 1) - 1);
    if (value == -1) {
        s_text.innerHTML = date.addMonth(-1).Format("yyyy-MM") + monthValue;
    } else {
        if (date.Format("MM") == new Date().Format("MM") && date.Format("yyyy") == new Date().Format("yyyy")) return;
        s_text.innerHTML = date.addMonth(1).Format("yyyy-MM") + monthValue;
    }
    tree.load({
        task_name_: mini.get("txt_key").getValue(),
        datetime: s_text.innerHTML.substr(0, s_text.innerHTML.length - 1)
    });
}
function SearchTask() {
    var div = document.getElementById("div_SearchPanel");
    if (div.style.display == '') {
        tree.load({
            task_name_: mini.get("txt_task_name_").getValue(),
            taskStartTimeStart: mini.get("txt_estimated_start_time_0").getText(),
            taskStartTimeEnd: mini.get("txt_estimated_start_time_1").getText(),
            taskEndTimeStart: mini.get("txt_estimated_end_time_0").getText(),
            taskEndTimeEnd: mini.get("txt_estimated_end_time_1").getText(),
            category_: mini.get("txt_category_id_").getValue(),
            task_Status_: mini.get("cmbTaskStatus").getValue(),
            task_property_: mini.get("txt_task_property_").getValue(),
            assign_user_name_: mini.get("txt_assign_user_name_").getValue(), //下达人
            manage_user_name_: mini.get("txt_manage_user_name_").getValue(),
            cc_: mini.get("txt_cc_").getValue()
        });
    }
    else {
        tree.load({
            task_name_: mini.get("txt_key").getValue(),
            datetime: s_text.innerHTML.substr(0, s_text.innerHTML.length - 1)
        });
    }
}
function onBeforeOpen(e) {
    var tree = mini.get("treegrid");
    var menu = e.sender;

    var editItem = mini.getbyName("edit", menu);
    var row = tree.getSelected();

    var rowIndex = tree.indexOf(row);

    if (!row) {
        e.cancel = true;
        //阻止浏览器默认右键菜单
        e.htmlEvent.preventDefault();
        return;
    }
    if (row) {
        $.ajax({
            url: "/AJAX/AjaxService.aspx?method=GetSession",
            type: "post",
            cache: false,
            success: function (text) {
                var user = mini.decode(text);
                if (row.assign_user_id_ == user.UserID || row.manage_user_id_ == user.UserID && (row.assist_user_id_ == null)) {
                    editItem.show();
                    editItem.enable();
                }
                else {                   
                    editItem.disable();
                    return;
                }
            }
        });

    }
}